#!/bin/bash







CONTAINER="Qwen3"
#export docker_name="Qwen"
File_path="/data"
docker_image="swr.cn-south-1.myhuaweicloud.com/ascendhub/mindie:2.0.RC2-300I-Duo-py311-openeuler24.03-lts"
docker run -itd --name $CONTAINER --ipc=host --net=host   \
--device=/dev/davinci0 \
--device=/dev/davinci1 \
--device=/dev/davinci2 \
--device=/dev/davinci3 \
--device=/dev/davinci4 \
--device=/dev/davinci5 \
--device=/dev/davinci6 \
--device=/dev/davinci7 \
--device=/dev/davinci_manager \
--device=/dev/devmm_svm \
--device=/dev/hisi_hdc \
-v /usr/local/dcmi:/usr/local/dcmi \
-v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \
-v /usr/local/Ascend/driver/lib64/common:/usr/local/Ascend/driver/lib64/common \
-v /usr/local/Ascend/driver/lib64/driver:/usr/local/Ascend/driver/lib64/driver \
-v /etc/ascend_install.info:/etc/ascend_install.info \
-v /etc/vnpu.cfg:/etc/vnpu.cfg \
-v /usr/local/Ascend/driver/version.info:/usr/local/Ascend/driver/version.info \
-v $File_path:$File_path \
$docker_image \
 /bin/bash




# 定义容器名称
#CONTAINER="Qwen3"


# 检查容器是否运行
if ! docker ps -q -f name="$CONTAINER" | grep -q .; then
    echo "错误: 容器 '$CONTAINER' 未运行"
    exit 1
fi
docker cp  /data/config_2.0.RC2-300I-Duo-py311-openeuler24.03-lts.json  $CONTAINER:/usr/local/Ascend/mindie/latest/mindie-service/conf/config.json
# 在容器内执行命令序列
docker exec -i "$CONTAINER" bash <<'EOF'
set -e  # 命令失败时立即退出
#source ~/.bashrc
#source /root/miniconda3/etc/profile.d/conda.sh
#conda activate python310
#source /usr/local/Ascend/ascend-toolkit/set_env.sh
#source /usr/local/Ascend/nnal/atb/set_env.sh
#source /usr/local/Ascend/atb-models/set_env.sh
#source /usr/local/Ascend/mindie/set_env.sh


# 复制配置文件
#cp /root/miniconda3/envs/python310/lib/libpython3.10.so.1.0 /usr/lib/

chmod -R 640 /usr/local/Ascend/mindie/latest/mindie-service/conf/config.json
# 启动服务（后台运行并保存日志）
cd /usr/local/Ascend/mindie/latest/mindie-service/
nohup ./bin/mindieservice_daemon >/data/1.log 2>&1 &

# 可选：等待服务启动（根据实际情况调整）
sleep 5

# 验证服务是否运行
if ! pgrep -f mindieservice_daemon >/dev/null; then
    echo "错误: mindieservice_daemon 未成功启动"
    exit 1
fi

echo "服务已成功启动"
EOF

# 可选：检查日志文件
echo "查看服务日志: docker exec -it $CONTAINER tail -f /data/1.log"
tail -f /data/1.log
